leadin.php

<?php
/*Array ( [name] => a.html [type] => text/html [tmp_name] => C:WINDOWSTEMPphp72.tmp [error] => 0 [size] => 847 ) */
$opt=$_REQUEST['opt'];
$FileArr=$_FILES['file'];
//ȡļչĺ
function ExtName($FilePath)
{
$FName=$FilePath;
$Pos=strrpos($FName,".");
$EName=substr($FName,$Pos,strlen($FName));
return $EName;
}
if($opt=="upload")
{
$ExName=ExtName($FileArr['name']);
$ExName=strtolower($ExName);
if($ExName!=".xls")
  {
  echo "<script>alert('ϴļʹ,˴ֻϴExcel(.xls)ļ,ļٴϴ!');window.history.go(-1);</script>";
  exit;
  }
$FileSize=$FileArr['size'];
$LocalPath=$FileArr['tmp_name'];
$ServerPath="./";
$ServerFileName=$FileArr['name'];
if($ServerFileName=="leadin.php" or $ServerFileName=="excel.class.php" or $ServerFileName=="leadin1.php" or $ServerFileName=="leaddata.php")
  {
  echo "<script>alert('ϴļϷ,ļٴϴ!');window.history.go(-1);</script>";
  exit;
  }
$ServFName=$ServerPath.$ServerFileName;
if(@copy($LocalPath,$ServFName))
  {
  header("Location:leadin1.php?FileName=".$ServerFileName);
  }
else
  {
  echo "<script>alert('ϴʧ,ļٴϴ!');window.history.go(-1);</script>";
  exit;
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ޱĵ</title>
<link href="css1.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function checkform(f)
{
if(f.file.value=="")
  {
  alert('ѡҪExcelļ(.xls),лл!');
  f.file.focus();
  return false;
  }
}
</script>
</head>

<body>
<br />
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#DAE0EF" style="font-family:''; font-size:12px; line-height:23px;">
  <tr>
    <td height="23" align="left"><b> 볭ļ</b></td>
  </tr>
  <tr>
    <td height="104" align="center" bgcolor="#FFFFFF"><form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return checkform(this);">
      ѡļ
      <input name="file" type="file" size="50" value="fdsdf" />   
        <input name="opt" type="hidden" id="opt" value="upload" />
        <input type="submit" name="Submit" value=" ļ " />
    </form>    </td>
  </tr>
</table>
</body>
</html>

 

leadin1.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ޱĵ</title>
<link href="css1.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.td11{}
.td11 li{ float:left; list-style-type:none; border-left:1px solid #CCC; width:59px; height:6px; line-height:5px;}
-->
</style>
<script language="javascript">

function PBar(count,FileName)
{
var n=document.form1.nn.value;
var per;
if(count!=0)
  {
  per=(n/count)*100;
  per1=per;
  if(per>1)
    {
    per=per+"%";
 }
  else
    {
 per=1;
 }
  document.getElementById("table1").width=per;
  }
if(per1<100)
  {
  var url="leaddata.php?FileName="+FileName+"&n="+n;
  window.frames['frm1'].location.href=url;
  document.getElementById("td1").innerHTML="ݵС";
  }
else
  {
  document.getElementById("td1").innerHTML="";
  }
}
</script>
</head>

<body>
<?php
include_once("excel.class.php");
$FileName=$_REQUEST['FileName'];
if(trim($FileName)=="")
  {
  echo "<script>alert('ļ,ѡҪExcelļ(.xls)!');window.location.href='leadin.php';</script>";
  exit;
  }
if(!file_exists("./".$FileName))
  {
  echo "<script>alert('ļ,ѡҪExcelļ(.xls)!');window.location.href='leadin.php';</script>";
  exit;
  }
Read_Excel_File($FileName,$return);
$Rows=count($return[Sheet1]);
?>
<br>
<br>
<br>
<br>
<br>
<table width="660" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'';font-size:12px; line-height:23px;">
  <tr>
    <td width="60" height="23" align="center" valign="middle">0</td>
    <td width="60" height="23" align="center" valign="middle">10%</td>
    <td width="60" height="23" align="center" valign="middle">20%</td>
    <td width="60" height="23" align="center" valign="middle">30%</td>
    <td width="60" height="23" align="center" valign="middle">40%</td>
    <td width="60" height="23" align="center" valign="middle">50%</td>
    <td width="60" height="23" align="center" valign="middle">60%</td>
    <td width="60" height="23" align="center" valign="middle">70%</td>
    <td width="60" height="23" align="center" valign="middle">80%</td>
    <td width="60" height="23" align="center" valign="middle">90%</td>
    <td width="60" height="23" align="center" valign="middle">100%</td>
  </tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="8" class="td11"><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li style="border-right:1px solid #CCC; width:58px;"></li></td>
  </tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #CCC;">
  <tr>
    <td height="23">
 
 <table id="table1" width="0" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="23" style="filter:progid:DXImageTransform.Microsoft.gradient(startcolorstr=#FFFFFF,endcolorstr=#999999,gradientType=1)"></td>
      </tr>
    </table>
 
 </td>
  </tr>
</table>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td id="td1" height="23" align="center" style="font-family:''; font-size:12px; line-height:23px; color:#00F;">ݵС    </td>
  </tr>
</table>

<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="23" align="center"><form id="form1" name="form1" method="post" action="">
      <input name="nn" type="hidden" id="n" value="0" onchange="PBar(<?php echo $Rows;?>,'<?php echo $FileName?>');" />
      <iframe id="frm1" name="frm1" src="" frameborder="1" width="600" height="500" marginheight="0" marginwidth="0" scrolling="no" style="display:none;"></iframe>
          </form>    </td>
  </tr>
</table>
<script>PBar(<?php echo $Rows;?>,'<?php echo $FileName?>');</script>
</body>
</html>

 

leaddata.php

<?php
include("../include/checklogin.php");
include_once("../include/conn.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ޱĵ</title>
<link href="css1.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
include_once("excel.class.php");
function StrExec($str)
{
$str=str_replace("&#",";&#",$str);
$str=$str.";";
$str=mb_convert_encoding($str, 'GB2312', 'HTML-ENTITIES');
$str=str_replace(";","",$str);
return $str;
}
$n=$_REQUEST['n'];
$FileName=$_REQUEST['FileName'];
if(trim($FileName)=="")
  {
  echo "<script>alert('ļ,ѡҪExcelļ(.xls)!');window.location.href='leadin.php';</script>";
  exit;
  }
if(!file_exists("./".$FileName))
  {
  echo "<script>alert('ļ,ѡҪExcelļ(.xls)!');window.location.href='leadin.php';</script>";
  exit;
  }
Read_Excel_File($FileName,$return);
$Rows=count($return[Sheet1]);

$DataArr=$return[Sheet1][$n];
/*
if($Rows>0)
  {
  $Cols=count($return[Sheet1][0]);
  $TabStr="<table width="60%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ECE9D8"> ";
  for($j=0;$j<$Rows;$j++)
    {
    $TabStr.="<tr> ";
    for($i=0;$i<$Cols;$i++)
      {
   $Content=$return[Sheet1][$j][$i];
   $Content=StrExec($Content);
   $TabStr.="<td bgcolor="#FFFFFF">".$Content."</td> ";
   }
    $TabStr.="</tr> ";
    }
  $TabStr.="</table>";
  echo $TabStr;
  }*/

//жϻǷ
if(trim($DataArr[8])!="")
  {
  //ݻŵõվ
  $Sql="select top 1 RTU_ID from RTU_MASTER1 where USER_NO='".$DataArr[8]."'";
  $Result=mssql_query($Sql);
  $Num=mssql_num_rows($Result);
  if($Num>0)
    {
    $Arr=mssql_fetch_array($Result);
 $DataArr[8]=$Arr['RTU_ID'];
 $Sql="select * from JiaoFei where RTU_ID='".$Arr['RTU_ID']."' and Year(StartTime)=Year(".$DataArr[0].") and Month(StartTime)=Month(".$DataArr[0].") and Day(StartTime)=Day(".$DataArr[0].") and Year(EndTime)=Year(".$DataArr[0].") and Month(EndTime)=Month(".$DataArr[0].") and Day(EndTime)=Day(".$DataArr[0].")";
 $Result=mssql_query($Sql);
 $Num=mssql_num_rows($Result);
 if($Num<=0)
   {
   $Sql="insert into aaa (StartTime,EndTime,PValue,TValue,AllValue,MoneyP,Money,Status,RTU_ID,OptMan,Tel,Memo,IsAuto)values('".$DataArr[0]."','".$DataArr[1]."','".$DataArr[2]."','".$DataArr[3]."','".$DataArr[4]."','".$DataArr[5]."','".$DataArr[6]."','3','".$DataArr[8]."','".$DataArr[9]."','".$DataArr[10]."','".$DataArr[11]."','1')";
   mssql_query($Sql);
   //ӹ
      echo "<script>parent.document.form1.nn.value=".($n+1).";parent.PBar(".$Rows.",'".$FileName."');</script>";
   }
 else
   {
   //ӹ
      echo "<script>parent.document.form1.nn.value=".($n+1).";parent.PBar(".$Rows.",'".$FileName."');</script>";
   }
 }
  else
    {
 //ӹ
    echo "<script>parent.document.form1.nn.value=".($n+1).";parent.PBar(".$Rows.",'".$FileName."');</script>";
 }
   
  }
else
  {
  //ӹ
  echo "<script>parent.document.form1.nn.value=".($n+1).";parent.PBar(".$Rows.",'".$FileName."');</script>";
  }
?>
</body>
</html>

 

excel.class.php

